/*
 * Module 02
 *
 */

package ua.gl.basecamp.tabachnyy.util;

import ua.gl.basecamp.tabachnyy.testcase.Question;
import ua.gl.basecamp.tabachnyy.testcase.UserAnswer;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.List;
import java.util.Scanner;

/**
 * @author yaroslav.tabachnyy@gmail.com
 * @version 1.02
 * @date 14.02.2013
 *
 */
public class TesterIO {
    private InputStream in;
    private OutputStream out;

    public TesterIO(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    public void outQuestion(Question question) {
        PrintStream printStream = new PrintStream(out);
        printStream.print(question);
    }

    public void outResult(double score) {
        PrintStream printStream = new PrintStream(out);
        printStream.format("Your score: %.2f points", score);
    }

    public List<UserAnswer> getUserAnswers(Question question) {

        PrintStream printStream = new PrintStream(out);
        printStream.print("Answer: ");

        Scanner scanner = new Scanner(in);
        String stringAnswer = scanner.nextLine();

        return question.getAnswersFromString(stringAnswer);
    }
}
